﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;

using InfFront.InfoSources.Base;

namespace InfFront.InfoSources.ADO
{
    public class DataColumnInfoField : InfoField
    {
        #region Private members
        private string columnName;
        #endregion

        #region Initialization/Construction
        public DataColumnInfoField()
        {
        }

        public DataColumnInfoField(IContainer container)
            : base(container)
        {
            container.Add(this);
        }
        #endregion Initialization/Construction

        [Category("General")]
        public string ColumnName
        {
            get { return columnName; }
            set { columnName = value; }
        }

        public override object GetValue(object obj)
        {
            var row = (DataRow)obj;
            var val = row[ColumnName];
            if (val == DBNull.Value)
                val = null;
            return val;
        }

        public override void SetValue(object obj, object value)
        {
            var row = (DataRow)obj;
            if (value == null)
                value = DBNull.Value;
            row[ColumnName] = value;
        }
    }
}
